package com.example.springboot.common.vo;

import com.example.springboot.entity.SysMenu;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class TreeMenu {

	public Long id;
	public String name;
	public String title;
	public List<TreeMenu> children;

	public static List<TreeMenu> TreeBuild(List<SysMenu> menuList, Long id) {

		List<TreeMenu> treeMenuList = new ArrayList<>();

		List<SysMenu> menuList1 = new ArrayList<>();
		
		for (SysMenu menu : menuList) {
			if (menu.getParentid() == id) {
				menuList1.add(menu);
			} else {
				continue;
			}
		}

		for (SysMenu menu : menuList1) {
			TreeMenu treeMenu = new TreeMenu();
			treeMenu.setId(menu.getId());
			treeMenu.setName(menu.getName());
			treeMenu.setTitle(menu.getName());
			treeMenu.setChildren(TreeBuild(menuList, menu.getId()));
			treeMenuList.add(treeMenu);
		}
		return treeMenuList;
	}
}
